﻿namespace Common.DataModels;
/// <summary>
/// 通过controller 返回的格式
/// </summary>
/// <typeparam name="T"></typeparam>
public  class MessageModel<T> 
{
    /// <summary>
    /// 数据
    /// </summary>
    public T data { get;  set; }
    /// <summary>
    /// 是否成功
    /// </summary>
    public bool success { get;  set; } = true;
    /// <summary>
    /// 状态码
    /// </summary>
    public int status { get; set; } = 200;
    /// <summary>
    /// 分页插叙时返回的数量
    /// </summary>
    public int count { get; set; } = 0;
    /// <summary>
    /// 消息
    /// </summary>
    public string msg { get;  set; }
    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="data">数据</param>
    /// <param name="success">是否成功</param>
    /// <param name="status">状态码</param>
    /// <param name="msg">消息</param>
    /// <param name="count">分页查询时的数量</param>
    public MessageModel(T data,bool success, int status, string msg,int count=0)
    {
        this.data = data;
        this.success = success;
        this.status = status;
        this.msg = msg;
        this.count = count;
    }

    public MessageModel(string msg,T data,int count)
    {
        this.data = data;
        this.msg = msg;
        this.count = count;
    }
    /// <summary>
    /// 成功
    /// </summary>
    /// <param name="data"></param>
    /// <param name="count">分页查询的数量</param>
    /// <returns></returns>
    public static MessageModel<T> Success(string msg, T data,int count=0)
    {
        return new MessageModel<T>(msg,data,count);
    }
    /// <summary>
    /// 失败
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    public static MessageModel<T> Fail(T data,string msg)
    {
        return new MessageModel<T>(data, false, 500,msg);
    }
    /// <summary>
    /// 其他code马格式的失败
    /// </summary>
    /// <param name="data"></param>
    /// <param name="code"></param>
    /// <returns></returns>
    public static MessageModel<T> FailWithCode(T data,int code,string msg)
    {
        return new MessageModel<T>(data, false, code,msg);
    }
}

public class MessageModel
{
    public object data { get;  set; }

    public bool success { get;  set; } = true;
    public int code { get; set; } = 200;
    public string msg { get;  set; }
}